#登录业务

import allure
#导入和该业务有关的UI们
from page.page_ui1 import PageUI1
from page.page_ui2 import PageUI2
from page.page_ui3 import PageUI3

class ServiceLogin(object):

    def __init__(self,driver,base_url):
        #从test层接收driver和base_url
        self.driver=driver
        self.base_url=base_url

        #通过创建3个ui对象的方式，把driber、base_url传递给本业务有关的UI层
        self.page_ui1=PageUI1(self.driver,self.base_url)
        self.page_ui2 = PageUI2(self.driver, self.base_url)
        self.page_ui3 = PageUI3(self.driver, self.base_url)



    def service_login_001(self,d):
        #完成ui1 的活
        allure.attach("","打开首页")
        self.page_ui1.openUrl()
        allure.attach("", "点击首页的登录按钮")
        self.page_ui1.click_login()
        #完成ui2 的活
        self.page_ui2.openUrl()
        allure.attach("", f"输入账号：{d['zanhao']}")
        self.page_ui2.input_zanhao(d["zanhao"])
        allure.attach("", f"输入密码：{d['pwd']}")
        self.page_ui2.input_pwd(d["pwd"])
        self.page_ui2.click_login()
        #完成ui3 的活
        self.page_ui3.openUrl()
        siji=self.page_ui3.getNicenText() #"nswe，欢迎光临"
        allure.attach("", f"实际昵称={siji}")
        #生成截图，并保存到screen目录
        imgName=self.page_ui3.savePng3("登录",d["key"]) #"登录_K001_20240809093112"
        #把生成的图片添加到allure步骤中
        allure.attach(open(f"./screen/{imgName}.png", 'rb').read(), "本次截图",
                      allure.attachment_type.PNG)
        return siji==d["yuqi"]

    def service_login_002(self,d):
        # 完成ui1 的活
        self.page_ui1.openUrl()
        self.page_ui1.click_login()
        # 完成ui2 的活
        self.page_ui2.openUrl()
        self.page_ui2.input_zanhao(d["zanhao"])
        self.page_ui2.input_pwd(d["pwd"])
        self.page_ui2.click_login()
        siji=self.page_ui2.getErrorTipText()
        return  d["yuqi"] in siji

    def service_login_003(self,d):
        # 完成ui1 的活
        self.page_ui1.openUrl()
        self.page_ui1.click_login()
        # 完成ui2 的活
        self.page_ui2.openUrl()
        self.page_ui2.input_zanhao(d["zanhao"])
        self.page_ui2.input_pwd(d["pwd"])
        self.page_ui2.click_login()
        siji=self.page_ui2.getPwdClass() #"input_text       invalid-text"
        return d["yuqi"] in siji

    def service_login_004(self,d):
        # 完成ui1 的活
        self.page_ui1.openUrl()
        self.page_ui1.click_login()
        # 完成ui2 的活
        self.page_ui2.openUrl()
        self.page_ui2.input_zanhao(d["zanhao"])
        self.page_ui2.input_pwd(d["pwd"])
        self.page_ui2.click_login()
        siji=self.page_ui2.getZanhaoClass()
        return d["yuqi"] in siji


